home *** CD-ROM | disk | FTP | other *** search
Text File | 1997-09-11 | 3.4 KB | 109 lines | [TEXT/CWIE] |
- // IAStoreStream.h
- // Copyright: © 1994 - 1996 by Apple Computer, Inc., all rights reserved.
-
-
- // for implementing IAStorage on different file systems
- // implementations need only implement pure virtual members
- // clients should not use this directly, but rather use through an IAStorage
-
- #pragma once
- #ifndef IAStoreStream_h
- #define IAStoreStream_h
-
- #pragma import on
-
- #include "IACommon.h"
- #include "IAMutex.h"
-
- #pragma IA_BEGIN_EXPORTS
-
- class IAStoreStream : public IAObject {
- friend class IAOutputBlock;
- friend class IAInputBlock;
- friend class IAStorage;
- public:
- IAStoreStream();
- virtual ~IAStoreStream();
- // Returns a new storeStream read/writing the same store
- virtual IAStoreStream* Clone() = 0;
-
- virtual bool IsOpen() = 0;
- virtual bool IsWritable() = 0;
-
- IAMutex* GetMutex() const {return mutex;}
- protected:
- // ** Implementations of the following should lock the mutex while executing **
-
- // creates a new store
- virtual void Initialize() = 0;
- // opens an existing store, enabling changes when 'writable' is true
- virtual void Open(bool writeable) = 0;
-
- // flushes buffered output to disk
- virtual void Flush() = 0;
-
- // returns one greater than the last position currently occupied
- virtual uint32 GetEOF() = 0;
- // truncates or extends the storage to the requested length
- virtual void SetEOF(uint32 address) = 0;
-
- // ** Remaining are only called with the mutex already locked. **
-
- virtual void Write(uint32 address, const byte* data, uint32 length) = 0;
- virtual uint32 Read(uint32 address, byte* data, uint32 length) = 0;
-
- // Should be called by Flush() implementations.
- void MaybeFlushBuffer(); // write buffer if it's dirty & mark it clean
- private:
- /// ** The following are only used by our friends, IAOutputBlock, IAInputBlock & IAStorage.
-
- // returns the position where the next read or write will happen
- uint32 GetPosition() { return bufferPos + (nextByte - buffer); }
- // sets the position where the next read or write will happen
- // when writable, this will silently extend the file past EOF
- // blockSize sets the limit for reading or writing
- void SetPosition(uint32 address, uint32 blockSize);
-
- // i/o primitives
- // each increments the position by the number of bytes read or written
- // reads may not be alternated with writes without an intervening call reposition
- void WriteByte(byte b) {
- if (nextByte < endByte) {
- *(nextByte++) = b;
- } else WritePastEndOfBuffer(b);
- }
- byte ReadByte() {
- return nextByte < endByte ? *(nextByte++) : ReadPastEndOfBuffer();
- }
- void WriteUInt32(uint32 i);
- uint32 ReadUInt32();
- void WriteBytes(const void* b, uint32 l);
- void ReadBytes(void* b, uint32 l);
-
- // really private stuff
- byte* buffer; // the buffer
- byte* nextByte; // pointer to the next character to read in buffer
- byte* endByte; // pointer to the end of the buffer
- uint32 bufferSize; // amount to read/write
- uint32 bufferPos; // position of the first char in buffer
- uint32 blockEnd; // don't permit read/writes past this
- bool bufferDirty;
-
- byte ReadPastEndOfBuffer();
- void WritePastEndOfBuffer(byte b);
- IAMutex* mutex;
-
- IAStoreStream(IAStoreStream&); // don't define a copy constructor
- };
-
- IAExceptionCode StoreError = 'VSEr';
- IAExceptionCode StoreFull = 'VSFu';
- IAExceptionCode StorePastBlockEnd = 'VSPB';
- IAExceptionCode StorePastEOF = 'VSEo';
-
- #pragma IA_END_EXPORTS
-
- #pragma import reset
-
- #endif
-